﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HROReporting.Model.NFCDevices;
using HROReporting.Infrastructure.UnitOfWork;
using NHibernate;
using NHibernate.Criterion;
using HROReporting.Infrastructure.Querying;

namespace HROReporting.Repository.NHibernate.Repositories
{
    public class NFCDeviceRepository : Repository<NFCDevice, int>, INFCDeviceRepository
    {
        public NFCDeviceRepository(IUnitOfWork uow)
            : base(uow)
        {
        }

        public NFCDevice GetNFCDeviceByDeviceSerial(string deviceSerial)
        {
            ICriteria criteriaQuery = SessionFactory.GetCurrentSession()
                .CreateCriteria(typeof(NFCDevice))
                .Add(Expression.Eq(PropertyNameHelper
                .ResolvePropertyName<NFCDevice>
                (n => n.NFCDeviceSerial), deviceSerial));

            IList<NFCDevice> nfcDevices = criteriaQuery.List<NFCDevice>();
            NFCDevice nfcDevice = nfcDevices.FirstOrDefault();

            return nfcDevice;
        }
    }
}
